package com.lizhi.note.entity;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import jakarta.persistence.*;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.Pattern;
import jakarta.validation.constraints.Size;
import lombok.Data;
import org.hibernate.annotations.SQLDelete;
import org.hibernate.annotations.Where;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import java.util.HashSet;
import java.util.Set;

@Entity
@Table(name = "users",
        uniqueConstraints = {
                @UniqueConstraint(columnNames = "username"),
                @UniqueConstraint(columnNames = "phone")
        })
@EntityListeners(AuditingEntityListener.class)
@Data
@SQLDelete(sql = "UPDATE users SET deleted = id WHERE id = ?")
@Where(clause = "deleted = 0")
public class AppUserEntity extends BaseEntity{

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    /**
     * 用户名，唯一性
     */
    @NotBlank
    @Size(max = 20)
    private String username;

    /**
     * 用户实际姓名
     */
    @NotBlank
    @Size(max = 10)
    private String activeName;

    @NotBlank
    @Size(max = 11)
    @Pattern(regexp = "^1[3-9]\\d{9}$", message = "{Pattern.user.phoneNumber}")
    private String phone;

    @NotBlank
    @Size(max = 120)
    private String password;

    private String email;
}
